package com.ydlclass.ChannelHandler;

import com.ydlclass.ChannelHandler.handler.InboundHandler.MyChannelInboundHandlerAdapter;
import com.ydlclass.ChannelHandler.handler.InboundHandler.YrpcMessageResponseDecoderHandler;
import com.ydlclass.ChannelHandler.handler.OutboundHandler.YrpcMessageRequestEncodeHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;

/**
 * Initializer的初始化器
 * @Author duWenJian
 * @Date 2024/2/20 12:59
 * @Version 1.0
 */
public class ConsumerChannelInitializer extends ChannelInitializer<NioSocketChannel> {
    @Override
    protected void initChannel(NioSocketChannel ch) {
        // 日志处理handler
        ch.pipeline().addLast(new LoggingHandler(LogLevel.DEBUG));
        // Request消息编码器
        ch.pipeline().addLast(new YrpcMessageRequestEncodeHandler());
        // Response消息解码器
        ch.pipeline().addLast(new YrpcMessageResponseDecoderHandler());
        // 接受结果的handler,负责拿到最终结果
        ch.pipeline().addLast(new MyChannelInboundHandlerAdapter());
    }
}
